home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / LOADFILE.C < prev    next >
C/C++ Source or Header  |  1993-03-28  |  23KB  |  772 lines

  1. /*
  2.     loadfile.c - load an existing fractal image, control level
  3.     This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #ifdef XFRACT
  10. #include <unistd.h>
  11. #endif
  12. #include "fractint.h"
  13. #include "fractype.h"
  14. #include "targa_lc.h"
  15. #include "prototyp.h"
  16.  
  17. /* routines in this module    */
  18.  
  19. static int  find_fractal_info(char *,struct fractal_info *);
  20. static void load_ext_blk(char far *loadptr,int loadlen);
  21. static void skip_ext_blk(int *,int *);
  22. static void backwardscompat();
  23.  
  24. int filetype;
  25. int loaded3d;
  26.  
  27. extern char   maxfn;                    /* num trig functions if formula */
  28. extern int    showfile;         /* has file been displayed yet? */
  29. extern char   readname[];        /* name of fractal input file */
  30. extern char   far *resume_info;     /* pointer to resume info if alloc'd */
  31. extern int    resume_len;        /* length of resume info */
  32. extern int    adapter;
  33. extern int    calc_status;
  34. extern int    initmode;         /* initial video mode        */
  35. extern long   calctime;
  36. extern int    initbatch;        /* 1 if batch run (no kbd)  */
  37. extern int    maxit;
  38. extern int    initincr;         /* maxiter incrmnt        */
  39. extern char   usr_stdcalcmode;        /* pass mode            */
  40. extern int    fractype;         /* fractal type         */
  41. extern double xxmin,xxmax;        /* corner values        */
  42. extern double yymin,yymax;        /* corner values        */
  43. extern double xx3rd,yy3rd;        /* corner values        */
  44. extern double param[];             /* parameters            */
  45. extern int    fillcolor;        /* fill color: -1 = normal  */
  46. extern int    inside;            /* inside color: 1=blue     */
  47. extern int    outside;            /* outside color, if set    */
  48. extern int    finattract;        /* finite attractor option  */
  49. extern int    forcesymmetry;
  50. extern int    LogFlag;            /* non-zero if logarithmic palettes */
  51. extern int    rflag, rseed;
  52. extern int    usr_periodicitycheck;
  53. extern char   useinitorbit;
  54. extern _CMPLX initorbit;
  55. extern int    potflag;            /* continuous potential flag */
  56. extern int    pot16bit;
  57. extern double potparam[3];        /* three potential parameters*/
  58. extern double inversion[];
  59. extern int    decomp[];
  60. extern int    usr_distest;        /* non-zero if distance estimator   */
  61. extern int    distestwidth;
  62. extern int    init3d[20];        /* '3d=nn/nn/nn/...' values */
  63. extern char   usr_floatflag;        /* floating-point fractals? */
  64. extern char   floatflag;
  65. extern int    usr_biomorph;
  66. extern char   FormName[];
  67. extern char   LName[];
  68. extern char   IFSName[];
  69. extern int    bailout;            /* user input bailout value */
  70. extern int    previewfactor;
  71. extern int    xtrans;
  72. extern int    ytrans;
  73. extern int    red_crop_left;
  74. extern int    red_crop_right;
  75. extern int    blue_crop_left;
  76. extern int    blue_crop_right;
  77. extern int    red_bright;
  78. extern int    blue_bright;
  79. extern int    xadjust;
  80. extern int    eyeseparation;
  81. extern int    glassestype;
  82. extern int    display3d;        /* 3D display flag: 0 = OFF */
  83. extern int    overlay3d;        /* 3D overlay flag: 0 = OFF */
  84. extern int    viewwindow;        /* 0 for full screen, 1 for window */
  85. extern float  viewreduction;        /* window auto-sizing */
  86. extern float  finalaspectratio;     /* for view shape and rotation */
  87. extern int    xdots, ydots;        /* # of dots on the logical screen */
  88. extern int    viewxdots,viewydots;    /* explicit view sizing */
  89. extern int    save_system,save_release;
  90. extern int    Ambient;
  91. extern int    RANDOMIZE;
  92. extern int    haze;
  93. extern int    transparent[2];
  94. extern int    rotate_lo,rotate_hi;
  95. extern int far *ranges;
  96. extern int    rangeslen;
  97. extern int    invert;
  98. extern int    num_fractal_types;
  99. extern float  screenaspect;
  100. extern     double mxmaxfp;
  101. extern     double mxminfp;
  102. extern     double mymaxfp;
  103. extern     double myminfp;
  104. extern     int   zdots;
  105. extern     float originfp;
  106. extern     float depthfp;
  107. extern     float heightfp;
  108. extern     float widthfp;
  109. extern     float distfp;
  110. extern     float eyesfp;
  111. extern     int   neworbittype;
  112. extern     short juli3Dmode;
  113. extern     int   major_method;  /* inverse julia method */
  114. extern     int   minor_method;
  115.  
  116. static FILE *fp;
  117.  
  118. int fileydots, filexdots, filecolors;
  119. float fileaspectratio;
  120.  
  121. int skipxdots,skipydots;    /* for decoder, when reducing image */
  122.  
  123.  
  124. void loadfile_overlay() { }    /* for restore_active_ovly */
  125.  
  126. #ifdef XFRACT
  127. extern int decode_fractal_info();
  128. #endif
  129.  
  130. int read_overlay()    /* read overlay/3D files, if reqr'd */
  131. {
  132.    struct fractal_info read_info;
  133.    char oldfloatflag;
  134.    char msg[110];
  135.  
  136.    ENTER_OVLY(OVLY_LOADFILE);
  137.  
  138.    showfile = 1;        /* for any abort exit, pretend done */
  139.    initmode = -1;        /* no viewing mode set yet */
  140.    oldfloatflag = usr_floatflag;
  141.    loaded3d = 0;
  142.  
  143.    if(strchr(readname,'.') == NULL)
  144.       strcat(readname,".gif");
  145.  
  146.    if(find_fractal_info(readname,&read_info)) { /* didn't find a useable file */
  147.       sprintf(msg,"Sorry, %s isn't a file I can decode.",readname);
  148.       stopmsg(0,msg);
  149.       EXIT_OVLY;
  150.       return(-1);
  151.       }
  152.  
  153.    maxit    = read_info.iterations;
  154.    fractype    = read_info.fractal_type;
  155.    if (fractype < 0 || fractype >= num_fractal_types) {
  156.       sprintf(msg,"Warning: %s has a bad fractal type; using 0",readname);
  157.       fractype = 0;
  158.    }
  159.    curfractalspecific = &fractalspecific[fractype];
  160.    xxmin    = read_info.xmin;
  161.    xxmax    = read_info.xmax;
  162.    yymin    = read_info.ymin;
  163.    yymax    = read_info.ymax;
  164.    param[0]    = read_info.creal;
  165.    param[1]    = read_info.cimag;
  166.    save_release = 1100; /* unless we find out better later on */
  167.  
  168.    invert = 0;
  169.    if(read_info.version > 0) {
  170.       param[2]        = read_info.parm3;
  171.       roundfloatd(¶m[2]);
  172.       param[3]        = read_info.parm4;
  173.       roundfloatd(¶m[3]);
  174.       potparam[0]   = read_info.potential[0];
  175.       potparam[1]   = read_info.potential[1];
  176.       potparam[2]   = read_info.potential[2];
  177.       potflag        = (potparam[0] != 0.0);
  178.       rflag        = read_info.rflag;
  179.       rseed        = read_info.rseed;
  180.       inside        = read_info.inside;
  181.       LogFlag        = read_info.logmap;
  182.       inversion[0]  = read_info.invert[0];
  183.       inversion[1]  = read_info.invert[1];
  184.       inversion[2]  = read_info.invert[2];
  185.       if (inversion[0] != 0.0)
  186.      invert = 3;
  187.       decomp[0]     = read_info.decomp[0];
  188.       decomp[1]     = read_info.decomp[1];
  189.       usr_biomorph  = read_info.biomorph;
  190.       forcesymmetry = read_info.symmetry;
  191.       }
  192.  
  193.    if(read_info.version > 1) {
  194.       save_release  = 1200;
  195.       if (!display3d
  196.     && (read_info.version <= 4 || read_info.flag3d > 0
  197.         || (curfractalspecific->flags&PARMS3D) )) {
  198.      int i;
  199.      for (i = 0; i < 16; i++)
  200.         init3d[i] = read_info.init3d[i];
  201.      previewfactor     = read_info.previewfactor;
  202.      xtrans      = read_info.xtrans;
  203.      ytrans      = read_info.ytrans;
  204.      red_crop_left     = read_info.red_crop_left;
  205.      red_crop_right  = read_info.red_crop_right;
  206.      blue_crop_left  = read_info.blue_crop_left;
  207.      blue_crop_right = read_info.blue_crop_right;
  208.      red_bright     = read_info.red_bright;
  209.      blue_bright     = read_info.blue_bright;
  210.      xadjust     = read_info.xadjust;
  211.      eyeseparation     = read_info.eyeseparation;
  212.      glassestype     = read_info.glassestype;
  213.      }
  214.       }
  215.  
  216.    if(read_info.version > 2) {
  217.       save_release = 1300;
  218.       outside       = read_info.outside;
  219.       }
  220.  
  221.    calc_status = 0;      /* defaults if version < 4 */
  222.    xx3rd = xxmin;
  223.    yy3rd = yymin;
  224.    usr_distest = 0;
  225.    calctime = 0;
  226.    if(read_info.version > 3) {
  227.       save_release = 1400;
  228.       xx3rd      = read_info.x3rd;
  229.       yy3rd      = read_info.y3rd;
  230.       calc_status = read_info.calc_status;
  231.       usr_stdcalcmode = read_info.stdcalcmode;
  232.       usr_distest     = read_info.distest;
  233.       usr_floatflag   = read_info.floatflag;
  234.       bailout      = read_info.bailout;
  235.       calctime      = read_info.calctime;
  236.       trigndx[0]  = read_info.trigndx[0];
  237.       trigndx[1]  = read_info.trigndx[1];
  238.       trigndx[2]  = read_info.trigndx[2];
  239.       trigndx[3]  = read_info.trigndx[3];
  240.       finattract  = read_info.finattract;
  241.       initorbit.x = read_info.initorbit[0];
  242.       initorbit.y = read_info.initorbit[1];
  243.       useinitorbit = read_info.useinitorbit;
  244.       usr_period